<?php
/* ARCHIVES.INC.PHP by martin $ 2009/03/03 02:31:13
*/

checkADMIN();
define('EXCLUDE_NONDISC_COMMENTS', 0); // 未公開のコメントを含めるかどうか[含める:1, 含めない:0]

if(!isset($apres)) $apres = MODE_STATIC ? '/' : '';

$_ARTCL_BOX_FORMAT =<<<FORMAT

<div class="article" id="UID%_ARTCL_ID_%"><!--article-->
  <h2 class="article-title">
   <a href="%_ARTCL_PMLINK_%" title="PermaLink">%_ARTCL_TITLE_%</a>
  </h2>
  <p class="article-date">%_ARTCL_DATE_FORMAT[Y/n/j]_%</p>
  <p class="article-category">%_ARTCL_CATEGORY_%</p>
  <p class="article-cat-icon">%_ARTCL_CATEGORY_ICON_%</p>
  <div class="article-content">%_ARTCL_CONTENT_%</div><!--#article-content-->
  <p class="article-posted">
   &mdash; posted by %_ARTCL_AUTHOR_% at %_ARTCL_TIME_FORMAT[h:i a]_% &nbsp;<!--index.php?UID=%_ARTCL_ID_%-->
   %_ARTCL_COMMENT:Comment [%_CMT_NUM_%]:_%
   %_ARTCL_TRACKBACK:TrackBack [%_TB_NUM_%]:_%
  </p>
</div><!--#article-->

FORMAT;

function html2archives($yyyymm){
 global $apres, $back, $_SMILIES, $DIVISION;
 $log = LOG."$yyyymm".EXT;
 if(!is_file(PATH.$log)){
  return $DIVISION['header'] .= "<h4>ファイル: $log が見当たりません。</h4>";
 }

 $new = DB.$yyyymm.'.html';
 $LINES = file($log);
 $encode =strtolower(ENCODE);
 $title = BLOG_NAME.'::'.$yyyymm;
 $header = 'archive: '.date('Y/m', strtotime($yyyymm."01"));
 $gntime = date('D, d M Y H:i:s+09:00', time());
 $img_loc = ROOT_PATH;
 $img_dir = IMG_DIR;
 $att_dir = AFFIXED_DIR;
 $imgs = array();
 $contents_loc = ROOT_PATH;
 $generator = 'ppBlog '.PPBLOG_VERSION;
 $body = $script = '';
 
 $html =<<<__HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="content-type" content="text/html;charset=$encode">
<meta name="generator" content="$generator" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="imagetoolbar" content="no" />
<title>$title</title>
<script type="text/javascript">/*<![CDATA[*/
var d = document;
var ie = (d.selection && !window.opera) ? 1 : 0;

function o(id){return d.getElementById(id);}
function readMore(self){
 var ob = self.parentNode.childNodes[1]; // Thanks, Saru-san!
 if(ob.style.display!="block"){
  ob.parentNode.firstChild.title = '記事をたたむ';
  ob.parentNode.firstChild.innerHTML = '&laquo;やっぱり隠す';
  ob.style.display = "block";
 } else if(ob.style.display=="block") {
  ob.parentNode.firstChild.title = '続きをよむ';
  ob.parentNode.firstChild.innerHTML = '&raquo;続きを読む';
  ob.style.display = "none";
 }
}

function loadMedia(ob, movf, ftype){ /* from ppBlog v1.5.5 */
 var clsid;
 if(ob.href.match(/\.3gp|x\-mpeg/)){
  clsid = d.all ? 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"' :
               'type="video/3gpp" data="'+movf+'"';
 } else clsid = 'type="'+ftype+'" data="'+movf+'"';
 ob.style.display = "none";
 ob.parentNode.parentNode.innerHTML += '<div class="media-part">'
  + '<p title="動画へのダイレクトリンク">::<a class="media-link" href="'+movf+'">'+movf+'</a>::</p>'
  + '<object '+clsid+' width="176" height="160">'
  + '<param name="type" value="'+ftype+'" />'
  + '<param name="src" value="'+movf+'" />'
  + '<param name="autoplay" value="true" />'
  + '</object></div>';
}
function toggle(ob){
 var tar = ob.parentNode.nextSibling;
 tar.style.display = tar.style.display=="none" ? "block" : "none";
 ob.innerHTML = /\[\+\]/.test(ob.innerHTML) ? ob.innerHTML.replace('[+]', '[-]') : ob.innerHTML.replace('[-]', '[+]');
}
d.onclick = function(e){
 e = e || window.event; var m;
 tar = e.target ? e.target : e.srcElement;
 e.cancelDefault = true;
 if(tar.nodeName == 'A' && (m = /#(UID\d+$)/.exec(tar.href))){
  if(ie) e.returnValue = false; else e.preventDefault();
  o(m[1]).scrollIntoView(); return false;
 }
}
/*]]>*/</script>
<style type="text/css">
* {
  margin: 0; padding: 0;
  font-family: 'ヒラギノ丸ゴ Pro W4', 'メイリオ', Arial, Verdana, Osaka, MS P Gothic, sans-serif;
}
body {
  padding: 20px;
  font-size: 14px !important;
  background: #fff;
  color: #333;
}
/*------------------[ 汎用タグ ]--------------------------*/
li, dd, blockquote {
  margin-left: 1em;
}
form label {
  cursor: pointer;
}
fieldset {
  -moz-border-radius: 6px;
}
input, select, textarea {
  font-size: 100%;
}
:link,:visited { text-decoration:none }
a img,:link img,:visited img { border: none }
a:link, a:visited { color: #6a74a6; }
a:hover, a:active { 
  color: navy;  text-decoration: underline;
}
strong { color: #7b4d4b; }
em { font-style: italic; }
kbd {
  font: 500 12px verdana, arial, sans-serif;
}
acronym, abbr { cursor: help; }
h3,h4,h5,h6 { font-weight: normal; }
h1, h2, h3, h4, h5 {
  margin: 15px 0;
  text-align: center;
}
sup { color:crimson; font-size:90%;}
h1 { font-size: 220%; }
h2 { font-size: 190%; }
h3 { font-size: 130%; }
h4 { font-size: 110%; }
h5 { font-size: 100%; }
code { font-family: "Courier New", Courier, monospace; }
label { cursor: pointer; }
address {
  width :100%;  text-align: center;
  margin: 2em 0 1em 0;
  font: 500 13px Times New Roman;
}
/*------------------[ 汎用クラス ]--------------------------*/
.hidden { display: none !important; }
.jump { padding-right: 1em; cursor: pointer; background: url(Images/jump.png) no-repeat right top;
  display: block; width: 50px; float: right;
}
.center, .alert { width: 99%; text-align: center; margin: 30px auto; }
p.introduction {
  margin: 2em 0 3em 2em;
  font-size: 107%;
}
hr.clear { clear:both; height: 1px; padding-bottom: 1px; margin-bottom: -1px; border: none; width: 100%; visibility: hidden; }
.separator { clear: both; border: none; text-align: center; margin-top: 0px; background: url(Images/divider.png) no-repeat 50% top; }
ul.navigation-list { margin: 2em auto 5em auto; width: 80%; list-style-type: square; font-size: 97%; line-height: 1.5; }
ul.navigation-list li { list-style-type: square; letter-spacing: 1px;}
/* --------------------[ 記事ボックススタイル ]----------------------*/
.article {
  font-size: 95%;  line-height: 1.2;
  background: #fff;
  margin: 2em auto;  padding: 1px;  width: 90%;
}
.article-united { margin: 2em  auto; width: 90%; }
.article-united .article { /* 同日エントリー結合時の個別ボックス */
  margin: 0;
  width: 100%;
}
.article-category {
  font-size: 12px;
  margin-top: -2px;  padding-left: 2em;
}
.article-date {
  font: 800 22px georgia, arial, serif;
  color: #a6afc2;
  padding: 2px 10px 2px 0;
  text-align: right;
  margin-top: -45px;  margin-bottom: 10px;
}
.article-title {
  font: 800 18px 'ヒラギノ丸ゴ Pro W4', 'メイリオ', arial,  sans-serif;
  letter-spacing : 1px;  text-align: left;
  padding : 4px 0 2px 18px;
  margin-top: 0;  width: 80%;
  border-left: solid 25px #6a74a6;
}
* html .article-title { height: 1%; } /* for buggy IE */
.article-cat-icon img{
  float: right;  margin: -5px 20px 5px 5px;
}
div.article .article-title a, div.article .article-content a {
  text-decoration: none;
  color: #5e729e;
}
div.article .article-title a:hover,
div.article .article-content a:hover {
  text-decoration: underline;
}
div.article .article-content a.button:hover { color: navy; text-decoration: none; }
.article-content {
  line-height : 1.7;
  letter-spacing : 1px;
  padding: 1em 1em .5em 1em;
  font-size: 14px;
}
.article-content p { margin: .8em 0; }
* html .articel-content {height: 100%;}
* html .article-content br { /* for buggy IE */
  line-height: 1; letter-spacing: 0px;
}
.article .article-content p.cap:first-letter {
  font-size : 180%;
  font-weight : 600;
  color: navy;
}
.article-content ul, .article-content dl { /* 記事内リスト */
  margin: 1em 3em;
}
.article-content ul li { /* 記事内リスト */
  background: url(Images/dlmark.png) no-repeat left 3px;
  padding-left: 15px;
}
.article-content dl dt { background: none; margin-bottom: .8em; font-weight: 500; }
.article-content ol { /* 記事内orderedリスト */
  list-style-type: decimal;
}
.article span.readmore {
  cursor: pointer;
  color: navy;
  padding-left: 1em;
}
.article .article-icon { width: 16px; height: 11px; }
.article-content .headline-readmore { /*--[ ヘッドライン用 続きを読む ]--*/
  margin: 1em;
}
.article-content p.headline-readmore a {
  font-size: 93%;  color: navy;
  border: none;
}
.article-content p.headline-readmore a:hover {
  color: #ff0066;
  border-bottom: 1px dotted crimson;
  text-decoration: none;
}
.article-content p.headline-readmore a:hover:after {
  content: "≫";
}
.article-posted {
  clear: both;
  font: 500 12px arial;
  margin: 10px 0 0 40px;
  padding-right: 3em;
  height: 30px;
  color: #888;
  text-align: right;
}
.article .article-bottom {
  text-align : right;
  padding-right: 1em;
  background : #f8f8ff;
  margin-bottom: 1em;
  clear: both;
}
.article-united .article .article-bottom {  border: none; }
object {
  width: 93%;
  margin: auto;
  overflow: auto;
}
.draft { /*--[ ドラフト記事囲み用 ]--*/
  border: dashed 1pt crimson;
  height: 100%;
}
.draft:before, .draft-before {
  content: "未公開の記事です";
  color: crimson;
  font-size: 11px;
  padding: .3em 1em;
}
.article-content div.attached a { border: solid 1px #fff; }
.article-content div.attached a:link { border: solid 1px #fff; }
.article-content div.attached a:hover { border: solid 1px navy; text-decoration: none;}
.article-content div.media-part { 
  margin: auto; text-align: center;
  width: 177px;
  border: solid 1px #ddd;
}
/*------------------------[ 引用フォーマット ]-------------*/
div.quote { border-left : 2px solid #ddd; border-right : 2px solid #ddd; background-color : #fff;
  font-size : 95%; padding : 10px; margin: 1em auto; width: 90%; color : #00468c; clear: both;}
blockquote { font-size : 95%; padding : 10px; width: 90%; margin: 1em auto; color : #00468c; background: #f0efec; clear: both;}
blockquote dl { padding: 3px 10px 0px 10px; }
q { font-size : 12px; margin: 1em; color : #00468c; }
pre { width: 86%; margin: 1.5em auto; overflow: auto; border-left: 4px solid #84ac84; border-right: 2px solid #84ac84;
  background: snow; padding: 1em; font: 500 13px Trebuchet MS;}
code { font: 500 15px/1.4 courier new,Verdana, monospace; color: #2d542c; letter-spacing: 0.1px; }
ul.decimal { list-style-type: decimal; padding-left: 1em; background: #fff; font-size: 90%; margin: 2em; }
ul.decimal li { background-image: none; }
.underline { text-decoration: underline; }
.google-it { font : 600 13px 'Times New Roman',serif; color : #2020ff; cursor : pointer; }
dl dt { font-weight: 600; }
dl dd { padding: 0 2em 0 1em; margin-bottom: 0.8em; line-height: 145%; color: #444; }
dd a { text-decoration: underline; }
.attached { clear: both; color: #003264; margin-top: 20px; }
p.nextpage { color: crimson; font-size: 90%; padding-left: 1em;}
/* ------------------------[ コメント表示用 ]--------------------*/
.comment-button {
  margin: -2.5em 0 3em 10%;
}
.comments-div {
  text-align : left;
  font-size : 97%;
  margin: 0 auto; width: 90%;
  border-bottom: solid 2px slateblue;
}
.comments-div .comments-header, .trackbacks-header {
  padding-bottom: 2em;
  text-align: center;
  font-size: 120%;
  color: navy;
}
.comments-div a{
  text-decoration: underline;
}
.comments-div .comment-entry p{
  color: #555;
  text-align: left;
}
.comments-div a.No{
  font: 800 150% georgia, arial, sans-serif;
  text-decoration: none;
  padding-right: 10px;
}
.comments-div a.No:before { content: "#"; }
.comments-div .comment-entry {
  margin:0 auto auto 2em;
}
.comments-div .non-disclosure {
  border: 1px dotted #aaa;
}
.comments-div .non-disclosure:before {
  content: "[非公開]";
  font-size: 80%;
  color: crimson;
}
.comments-div .comment-index {
  padding-bottom: 0.5em;
}
.comments-div .comment-index-owner {
  margin:-1em auto 0.5em -1em;
}
.comments-div .comment-entry-owner {
  padding-left: 6em;
}
.comments-div .comment-body{
  margin: 0.5em 0 0 1em;  padding: 0 6em 0 1em;
  line-height: 1.5;
}
.comment-quote {
  color: #7e7a94;
  border-left: 2px #ddd solid;
  padding: 10px;
}
.comment-cntrl {
  padding-left: 0.5em;
}
.comment-cntrl img {
  vertical-align: middle;
}
.comment-owner {
  width: 18px; height: 18px;
  padding-left: 5px;
}
hr.comment-separator {
  border-width: 0;
  visibility: hidden;
  margin: 1em 0 0.5em 4em;
}
.comment-private {
  color: crimson;
  font-size: 80%;
}
.comment-close {
  margin: 1em 0 3em 10%;
}
/*------------------------[ 写真・ドロップシャドウ設定 ]-----------------*/
div.photo {
  padding: 15px; margin: 15px;
}
div.photo div.shadow {
  float: left;
}
div.photo div.shadow img, div.photo div.noshadow img {
  display: block;
  padding: 8px; margin: 0;
  border: 1px solid #ccc;
  border-color: #ddd #ccc #bbb #ccc;
  background-color: #fff;
  position: relative;
  left: -3px; top: -4px;
  overflow: hidden;
}
div.photo div.photo-caption {
  font-size: 13px; color: navy;
  padding: 0 2px 0 5px;
}
* html div.photo div.shadow { margin-bottom: -12px; }             /* just for IE6 */
*:first-child+html div.photo div.shadow { margin-bottom: -12px; } /* just for IE7 */
div.photo div.noshadow img.borderless { padding: 0; }
div.polaroid {
  padding: 11px 8px 10px 11px; margin: 15px;
}
div.polaroid div.shadow {
  margin: -9px -6px -4px -9px;
  padding: 9px 0 0 9px;
  border: 1px solid #ccc;
  border-color: #ddd #ccc #bbb #ccc;
  background: #fff;
}
div.polaroid img {
  border: 1px solid #ccc;
  border-color: #ddd #ccc #bbb #ccc;
}
div.polaroid div.photo-caption {
  font-size: 13px; color: navy;
  margin-bottom: 9px;
}
.al-left { float: left; }
.al-right { float: right;}
.al-center { margin: auto !important;}
</style>
<base href="$img_loc" />
</head>
<body id="weblog">
<h1>$header</h1>

__HTML;
 $body .= '<p style="padding: 10px 0 0 10em;">'.date('Y年m月', strtotime($yyyymm."01")).' は '.count($LINES).' 件の書き庫があります。</p>'.NL;
 $body .= '<ul class="navigation-list">'.NL;
 $CMTS_NUM = $PING_NUM = array();
 foreach ($LINES as $j=>$line){
  list($id,$cat,$title,) = explode('|', $line);
  $CMTS_NUM[$j] = '('.get_cmt_array($id, TRUE).')';
  $PING_NUM[$j] = '('.get_tb_count($id).')';
  $body .= '<li><a href="'.$yyyymm.'.html#UID'.$id.'">'.$title.'</a>&mdash; '.$cat.' <span class="georgia"> '
        .date('Y-m-d', str_replace('d', '', $id)).' &nbsp;'.$CMTS_NUM[$j].' '.$PING_NUM[$j].'</span></li>'.NL;
 }
 $body .= '</ul>'.NL;

 foreach ($LINES as $j=>$line){
  list($id,$cat,$title,$com,$author,$allowComment,$ping,$excerpt,$extended) = explode('|', $line);
  $cmts_array = array();
  if(!empty($extended)){
   $_extended = explode(',', $extended);
   foreach ($_extended as $i=>$_ext){
    $com .= '<!--END--><hr class="clear" /><p class="nextpage">[ここから'.($i+2).'ページ目]</p>'.$_ext;
   }
  }
  $com = preg_replace('{\[file:([^:]+?):([^/]*?)/\]}', "<p><a href=\"".ROOT_PATH."index.php?mode=download&amp;aim=$1\">[ファイル:$1]</a></p>", $com);
  $com = str_replace(array_keys($_SMILIES), '', $com);
  $com = NL._box($id, $cat, $title, $com.'<!--END-->',ONAME,0,0,array($CMTS_NUM[$j], 0),array($PING_NUM[$j], 0),'',1,0,1)."\n";
  if($allowComment){
   $cmts_array = get_cmt_array($id);
   if(!empty($cmts_array)){
    $parts = explode('|', $cmts_array[0]);
    $cmt_count = !EXCLUDE_NONDISC_COMMENTS ? $parts[3] : (int)($parts[3] - $parts[4]);
   } else $cmt_count = 0;
  } else $cmt_count = -1; # コメント受付なし

  $_com = NL;
  if($cmt_count >= 1) $_com .= '<p class="comment-button"><button type="button" onclick="toggle(this);return false;"> コメント '.$cmt_count.'件 [+] </button></p><div class="comments-div" style="display: none;">'.NL.'<p class="comments-header">この記事に対するコメント['.$cmt_count.'件]</p>'.NL;
  
  foreach ($cmts_array as $i => $c){
   $c_id = $c_name = $c_color = $c_com = $c_ip = $c_url = $c_mail = $c_nondisc = $mt = '';
   if($i==0) continue;
   $p = explode('|', $c);
   $c_id = $p[0]; $c_name = $p[1]; $c_color = $p[2]; $c_com = $p[3];
   $c_ip = isset($p[4]) ? $p[4] : ''; $c_url = isset($p[5]) ? $p[5] : '';
   $c_mail = !empty($p[6]) ? '<a href="mailto:'.my_decrypt($p[6]).'">[mail]</a>' : '';
   if($p[7]==1){
    if(!EXCLUDE_NONDISC_COMMENTS) continue;
    else $c_nondisc = ' non-disclosure';
   }
   $extlink = (ENABLE_NEW_WINDOW) ? ' onclick="window.open(this.href,\'\');return false;"' : '';
   $url = preg_match('{'.V_URL.'}', $c_url) ? ' <a href="'.$c_url.'"'.$extlink.'>[url]</a> ' : '';
   $c_com = preg_replace('{\[q\]`?(.*?)`?\[/q\]`?}is', NL.'<p class="comment-quote">\\1</p>'.NL, $c_com);
   $c_com = str_replace('`', '<br />', $c_com);
   if($c_name==ONAME || isRegisteredUser($c_name)){
    $_com .= ' <div class="comment-entry-owner">
  <p class="comment-index-owner"><span class="owner" id="CID'.$c_id.'"> &raquo; '.$c_name.$url.' &nbsp;'.date('Y/m/d h:i A', $c_id).'</span></p>
 <div class="comment-body" style="color:#'.$c_color.';">'.$c_com.'</div>
</div>
';
   } else {
    $_com .= ' <div class="comment-entry'.$c_nondisc.'">
 <p class="comment-index"><a class="No" id="CID'.$c_id.'" title="Permalink" href="index.php?UID='.$id.'#CID'.$c_id.'">'.$i.'.</a>&nbsp; '.$c_name.$url.$c_mail.' &mdash; '.date('Y/m/d h:i A', $c_id).' &nbsp;IP: '.$c_ip.'</p>
 <div class="comment-body" style="color:#'.$c_color.';">'.$c_com.'</div>
</div><!--#comment-entry-->
';
   }
   $_com .= '<hr class="comment-separator" />'.NL;
  } # foreach
  if($cmt_count >= 1){
   $_com .= '<p class="comment-close"><button type="button" onclick="var p = this.parentNode.parentNode,q=p.previousSibling;p.style.display=\'none\';q.firstChild.innerHTML = q.firstChild.innerHTML.replace(\'[-]\',\'[+]\');q.scrollIntoView();return false;">上のコメントを閉じる</button></p>';
   $_com .= '</div><!--#comments-div-->'.NL;
  }
  if(strpos($com, '<!--HIDE-->')){
   $com = preg_replace('{<!\-\-HIDE\-\->(.+?)(?:<!\-\-/HIDE\-\->|(<!\-\-END\-\->))}s', NL.'<div class="readmore-div"><span class="readmore" title="もっと読む" onclick=\'readMore(this);return false;\'>もっと読む&raquo;</span><div style="display:none">$1</div>'.NL.'$2</div>', $com);
  }

  $com = my_parser($com, ENABLE_BR);
  $com = preg_replace('{<img class="extlink-icon" .+/>}', '', $com);
  $com = preg_replace('{<p class="article\-posted">.*?</p>}s', '<!--{p.article-posted}-->', $com);
  $com = preg_replace('{<!\-\-.+<rdf:RDF.*?</rdf:RDF>.+?\-\->}s', '<!--RDF-->', $com);
  if(preg_match_all('{<img (?:class="borderless" |)src="(PIX/[^"]+?)"[^>]+?/>}i', $com, $mt)){ // 画像を含むとき
   foreach ($mt[1] as $i=>$imgf){
    if(is_file($imgf)){
     $size = getImageSize($imgf);
     $imgs[][$imgf] = $size['mime'];
    }
   }
   $com = preg_replace('{ onclick="imagePop\(event, .PIX/([^,]+?),.+?\);"}', ' onclick="window.open(\''.$img_loc.'PIX/\\1, \'\');"', $com);
  }
  if(preg_match_all('{<a href="media/}i', $com, $mt)){ // 動画を含むとき
   foreach ($mt[0] as $i=>$mov_dir){
    $com = str_replace("<a href=\"$mov_dir/","<a href=\"{$img_loc}$mov_dir/", $com);
   }
  }
  $body .= ($com.$_com);
 } #foreach
 if($DIVISION['script'] != ''){
  $html = str_replace('</style>', '</style>'.$DIVISION['script'], $html);
 }
 $body .= '<address>ppBlog::html2archives generator</address>'.NL;
 $html .= $body;
 $fp = fopen($new, 'ab');
 fwrite($fp, $html);
 fclose($fp);
  if(!empty($imgs)){
  $script .= '
<script type="text/javascript">
 var imgs = [
  ';
  $fp = fopen($new, 'ab');
  fwrite($fp, $script);
  fclose($fp);

  foreach ($imgs as $j =>$_img){
   $script = '';
   $imgf = array_keys($_img);  $imgf = array_shift($imgf);
   $mime = array_values($_img);$mime = array_shift($mime);
   $img = str_replace($img_loc, "", $imgf);
   $img = chunk_split(base64_encode(fread(fopen($img, "rb"), filesize($img))), 256000);
   $imgData = explode("\r\n", $img);
   $script .= "'data:$mime;base64,";
   foreach ($imgData as $img){
    $script .= $img."'+\n'";
    unset($img);
   }
   $script .= "',\n";
   $fp = fopen($new, 'ab');
   fwrite($fp, $script);
   fclose($fp);
   unset($imgData, $script);
  } #foreach
  $script = '';
  $script .= '""];';
  $script .= '
 var IMG = d.getElementById("weblog").getElementsByTagName("IMG");
 var bg = "url(\''.str_pad('', 253*4, '09PT').'09PSH5BAEAAAEALAAAAAAKAAoAAAgfAAEEEEhwYACDBQkmRHhwoUKGBSEidGhQ4kOKFgcGBAA7\')";
 window.onload = function(){
 for (var j = 0, i = 0, len = IMG.length - 1; i < len; i++){
  if(/PIX\//.test(IMG[i].src)){
   IMG[i].src = imgs[j];
   if(IMG[i].parentNode.className == "shadow"){
    if(IMG[i].parentNode.parentNode.className.indexOf("photo") != -1){
     IMG[i].parentNode.style.background = bg;
    }
   }
   if(IMG[i].parentNode.parentNode.className.indexOf("polaroid") != -1){
    IMG[i].parentNode.parentNode.style.background = bg;
   }
   j++;
  }
 }
}
';
  $script .= '</script>'.NL;
  $fp = fopen($new, 'ab');
  fwrite($fp, $script);
  fclose($fp);
 }

 $fp = fopen($new, 'ab');
 fwrite($fp, '</body>'.NL.'</html>'.NL);
 fclose($fp);
 $fsize = filesize(PATH.$new);
 header("Content-length: $fsize"); 
 header("Content-Type: application/octet-stream; name=\"".basename($new)."\"");
 header("Content-Disposition: attachment; filename=\"".basename($new)."\"");
 readfile(PATH.$new);
 unlink(PATH.$new);
 update_ARCHIVES($yyyymm, time(), $fsize, true);
 exit;
}

?>